package com.qiang.test13;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Demo02 {
    public static void main(String[] args) throws IOException {
      /*  File file = new File("lianxi\\aa.txt");
        //boolean newFile = file.createNewFile();
        //System.out.println(newFile);

        FileOutputStream fs = new FileOutputStream("lianxi\\aa.txt",true);
        fs.write(12);
        fs.write(97);
        fs.close();*/

       /* File file = new File("D:\\qwe");
        //boolean mkdir = file.mkdir();
        //System.out.println(mkdir);
        File file1 = new File(file, "\\a.txt");
        file1.createNewFile();

        FileOutputStream fs = new FileOutputStream(file1);
        fs.write(100);fs.close();*/


        //删除文件夹

        File f1 = new File("D:\\qwe");

        deleteDir(f1);
    }

    private static void deleteDir(File f1) {

        //获取文件列表

        File[] f2 = f1.listFiles();

        //遍历，判断是否是文件

        for (File f3 : f2) {

            if (f3.isFile()) {
                f3.delete();
            } else {
                deleteDir(f3);
            }

        }
        f1.delete();
    }
}
